<?php
namespace app\api\controller;
use think\Controller;
use think\Session;

class Clubs extends Controller
{
    public function getList(){
        $result=db('clubs')->select();
        if($result)
        {
            echo json_encode($result);
        }
        else
            echo json_encode(['0']);
        die();

    }

    public function getDetail()
    {
        $id=input('id');
        $result=db('clubs')->find($id);
        if(Session::has('uid'))
        {
            $result_foucus=db('foucus')->where('cid',$id)->where('uid',Session::get('uid'))->find();
            if($result_foucus)
                $result['flag']=1;
            else
                $result['flag']==0;
        }
        else
            $result['flag']=0;
        echo json_encode($result);
        die();
    }
        public function focus()
    {
        $id=input('id');
        if(Session::has('uid'))
        {
            $a=db('focus')->where('uid',Session::get('uid'))->where('cid',$id)->find();
            if($a){
                echo json_encode(['status'=>0,'message'=>'You have paid attention to the club']); 
                //(您已关注此俱乐部)
                die();
            }

            $result=db('focus')->insert(['uid'=>Session::get('uid'),'cid'=>$id]);
            if($result)
            {
            echo json_encode(['status'=>1,'message'=>'Success']);
            }
            else
            echo json_encode(['status'=>0,'message'=>'Database operation failed, please contact the administrator']);
        //(数据库操作失败，请联系管理员)
        }
        else
             echo json_encode(['status'=>0,'message'=>'You are not landing']);
        die();
    }
     public function cancel()
    {
       $id=input('id');
        if(Session::has('uid'))
        {
            $a=db('focus')->where(['cid'=>$id,'uid'=>Session::get('uid')])->find();
            if(!$a){
                echo json_encode(['status'=>0,'message'=>'You dont pay attention to this club']); 
                //您没关注此俱乐部
                die();
            }
            
            $result=db('focus')->delete($a);
            if($result)
            {
            echo json_encode(['status'=>1,'message'=>'Success']);
            }
            else
            echo json_encode(['status'=>0,'message'=>'Database operation failed, please contact the administrator']);
        //数据库操作失败，请联系管理员
        }
        else
             echo json_encode(['status'=>0,'message'=>'You are not landing']);
         //您没登录
        die();
    }

}
